package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup
var a []int
var b chan int // 需要指定通道中元素的类型

func noBufChannel() {
	fmt.Println(b)     // <nil>
	b = make(chan int) // 不带缓冲区通道初始化
	wg.Add(1)
	go func() {
		defer wg.Done()
		x := <-b
		fmt.Println("后台goroutine从通道中取到了", x)
	}()
	b <- 10
	fmt.Println("10发送到通道b中了...")
	b = make(chan int, 16) // 带缓冲区通道初始化
	fmt.Println(b)         // 0xc00005a060
	wg.Wait()
}
func bufChannel() {
	fmt.Println(b)          // <nil>
	b = make(chan int, 100) // 带缓冲区通道初始化
	b <- 10
	fmt.Println("10发送到通道b中了...")
	x := <-b
	fmt.Println("从通道中取到了", x)
}

func main() {
	noBufChannel()
	//bufChannel()
}
